package com.ryan.mms.privilage.model;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.ryan.framework.model.Model;

/**
 * Resource entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "resource", catalog = "framework")
public class Resource implements Model{

	private static final long serialVersionUID = 1L;

	// Fields

	private Long resourceId;
	private String resourceCode;
	private String resourceName;
	private Integer resourceType;
	private Long parentResourceId;
	private String resourceDescription;
	private String defaultUrl;
	private Integer status;
	private Date createTime;
	private Date lastModifyTime;
	private Application application;
	
	// Constructors

	/** default constructor */
	public Resource() {
	}

	/** minimal constructor */
	public Resource(String resourceCode, String resourceName, Integer status) {
		this.resourceCode = resourceCode;
		this.resourceName = resourceName;
		this.status = status;
	}

	/** full constructor */
	public Resource(String resourceCode, String resourceName,
			Long parentResourceId, Integer resourceType, String resourceDescription,
			String defaultUrl, Integer status, Date createTime,
			Date lastModifyTime) {
		this.resourceCode = resourceCode;
		this.resourceName = resourceName;
		this.parentResourceId = parentResourceId;
		this.resourceType = resourceType;
		this.resourceDescription = resourceDescription;
		this.defaultUrl = defaultUrl;
		this.status = status;
		this.createTime = createTime;
		this.lastModifyTime = lastModifyTime;
	}

	// Property accessors
	@GenericGenerator(name = "generator", strategy = "increment")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "resource_id", unique = true, nullable = false)
	public Long getResourceId() {
		return this.resourceId;
	}

	public void setResourceId(Long resourceId) {
		this.resourceId = resourceId;
	}

	@Column(name = "resource_code", nullable = false, length = 64)
	public String getResourceCode() {
		return this.resourceCode;
	}

	public void setResourceCode(String resourceCode) {
		this.resourceCode = resourceCode;
	}

	@Column(name = "resource_name", nullable = false, length = 128)
	public String getResourceName() {
		return this.resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	@Column(name = "parent_resource_id")
	public Long getParentResourceId() {
		return parentResourceId;
	}

	public void setParentResourceId(Long parentResourceId) {
		this.parentResourceId = parentResourceId;
	}

	@Column(name = "resource_type")
	public Integer getResourceType() {
		return this.resourceType;
	}

	public void setResourceType(Integer resourceType) {
		this.resourceType = resourceType;
	}

	@Column(name = "resource_description", length = 256)
	public String getResourceDescription() {
		return this.resourceDescription;
	}

	public void setResourceDescription(String resourceDescription) {
		this.resourceDescription = resourceDescription;
	}

	@Column(name = "default_url", length = 256)
	public String getDefaultUrl() {
		return this.defaultUrl;
	}

	public void setDefaultUrl(String defaultUrl) {
		this.defaultUrl = defaultUrl;
	}

	@Column(name = "status", nullable = false)
	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "create_time", length = 10)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "last_modify_time", length = 10)
	public Date getLastModifyTime() {
		return this.lastModifyTime;
	}

	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}
	
	@ManyToOne( cascade = {CascadeType.PERSIST}, targetEntity=Application.class )
	@JoinColumn(name="application_id")
	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

}